package com.gimi.cloud.bbp.dao.dao.sys;

import com.gimi.cloud.bbp.dao.myMapper.MyMapper;
import com.gimi.cloud.bbp.dto.sys.SysMenuDTO;
import com.gimi.cloud.bbp.entity.sys.SysMenuEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by shazhiwei on 2017/12/14.
 */
@Mapper
public interface SysMenuDao extends MyMapper<SysMenuEntity>,BaseDao<SysMenuEntity,SysMenuDTO> {

    @Select("SELECT me_id,me_pid,me_name,me_link,me_icon FROM sys_menu where is_delete = 0")
    List<SysMenuDTO> getAllMenuList();

    @Select("SELECT me_id,me_pid,me_name,me_link,me_icon FROM sys_menu WHERE is_delete = 0 and me_id IN (SELECT me_id from sys_authority WHERE ro_id IN (SELECT ro_id FROM sys_master_role WHERE ma_id = #{maId}))")
    List<SysMenuDTO> getUserMenuList(@Param(value = "maId") Integer maId);

    /**
     * 根据父类ID获取菜单
     * @return
     */
    @Select("select t.*,(select IFNULL(count(1),0) from sys_menu where me_pid=t.me_id) has_child_menu from sys_menu t where is_delete=0 and me_pid=#{mePid}")
    List<SysMenuDTO> getMenuListByPid(@Param(value = "mePid") Integer mePid);

    /**
     * 根据父类获取菜单
     * mePids类似 (1,2,3)
     */
    @Select("SELECT * FROM sys_menu WHERE me_pid IN #{mePids};")
    List<SysMenuDTO> getMenuListByPids(@Param(value = "mePids") String mePids);

    @Select("SELECT * FROM sys_authority auth LEFT JOIN sys_menu menu ON auth.me_id = menu.me_id WHERE menu.is_delete = 0 AND auth.ro_id = #{roleId};")
    List<SysMenuDTO> getMenuListByRoleId(@Param(value = "roleId") Integer roleId);

    @Select("SELECT * FROM sys_menu WHERE is_delete = 0;")
    List<SysMenuDTO> getMenuList();

    @Select("SELECT * FROM sys_menu WHERE me_id = #{meId} AND is_delete = 0;")
    SysMenuDTO getMenuSingle(@Param(value = "meId") Integer meId);


}
